# 字符串是无法修改的数据容器
sentence = "Tom is a boy"
print(sentence[2])

# index
pos = sentence.index("boy")
print(pos)

# replace 替换全部指定字符(不会修改原字符串)，返回替换后的新字符串
new_sentence = sentence.replace("boy", "girl")
print(sentence)
print(new_sentence)

# split 分割字符串 返回列表
mylist = sentence.split(" ")
print(sentence)  # 原字符串不会被修改
print(type(mylist), mylist)
mylist2 = sentence.split("o")
print(mylist2)

# strip 字符串规整 去除首尾指定字符
sentence = "   hello world "
new_sentence = sentence.strip(" ")
print(new_sentence)
sentence = "hhhjjjhhhello world jhhjjh"
new_sentence = sentence.strip("hj")
print(new_sentence)

# count 元素计数
cnt = sentence.count("l")
print(cnt)

# len 长度
print(len(sentence))
